﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GenericTools;

namespace ReportingManagement.Components
{
    /// <summary>
    /// Interaction logic for OptionBPlusServiceProviderEditor.xaml
    /// </summary>
    public partial class OptionBPlusServiceProviderEditor : Window
    {
        private DataModels.Models.OptionBPlusFacility facilityInfo;

        public OptionBPlusServiceProviderEditor(DataModels.Models.OptionBPlusFacility facilityInfo, 
            string facilityName, string districtName, string regionName)
        {
            InitializeComponent();

            this.facilityInfo = facilityInfo;
            this.DataContext = this.facilityInfo;

            lblFacilityName.Content = facilityName;
            lblLocation.Content = string.Format("{0}, {1}", districtName, regionName);
            this.Title = string.Format("{0} - Option B+ Services", facilityName);
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                btnSave.IsEnabled = false;
                btnCancel.IsEnabled = false;
                bool saved = Utilities.SaveOptionBPlusServices(facilityInfo);
                if (saved) this.Close();
                else
                {
                    MessageBox.Show("Changes were not saved!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                btnSave.IsEnabled = true;
                btnCancel.IsEnabled = true;
            }
        }
    }
}
